package com.chengjue.transaction.learn.thread.countdownlatch;

import java.util.concurrent.CountDownLatch;

/**
 * 描述:
 * 使用countdownlatch
 *
 * @author Kipeng Huang
 * @create 2018-03-03 下午1:28
 */
public class CountRunnable implements Runnable {
	private CountDownLatch countDownLatch;

	public CountRunnable(CountDownLatch countDownLatch) {
		this.countDownLatch = countDownLatch;
	}

	/**
	 * countDownLatch.countDown();  放在finally中执行
	 */
	@Override
	public void run() {
		try {
			//打印线程名称
			System.out.println(Thread.currentThread().getName());
			System.out.println("开始处理数据...");
			Thread.sleep(3000L);
			System.out.println("数据处理完毕...");

		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			countDownLatch.countDown();
		}

	}
}
